home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 477 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.7 KB  |  88 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: oliva@grande.dcc.unicamp.br (Alexandre Oliva)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Proposal: Reconcile Inheritance and Inlining
  5. Date: 25 Feb 1996 00:06:05 GMT
  6. Organization: DCC - UNICAMP - Campinas, SP, Brazil
  7. Sender: oliva@grande.dcc.unicamp.br
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <or4tsgfvgl.fsf@grande.dcc.unicamp.br>
  10. References: <4gkas9$4o84@news-s01.ny.us.ibm.net>
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: grande.dcc.unicamp.br
  14. In-Reply-To: hickeyr@ibm.net's message of 23 Feb 1996 15:55:20 GMT
  15. X-Newsreader: Gnus v5.1
  16. Content-Length: 1761
  17. Originator: clamage@taumet
  18.  
  19. Rich Hickey writes:
  20.  
  21. > Proposal: Reconcile Inheritance and Inlining
  22. > --------------------------------------------
  23. > Rich Hickey
  24. > rich@rcs-hq.mhs.compuserve.com
  25.  
  26. > -----------------------------------------------------------------------
  27. > I propose that the explicit keyword be allowed as a qualifier of a class 
  28. > definition, such qualification taking the form of:
  29.  
  30. > explicit class X{
  31. >   //the definition of X
  32. >   };
  33.  
  34. > and that such qualification has the following meaning:
  35.  
  36. > For any class X defined as explicit -
  37.  
  38. > X cannot be derived from.
  39.  
  40. > Any calls to member functions of X, even through pointers or references 
  41. > to X, be called with the 'normal' function mechanism, i.e.  not the 
  42. > virtual function mechanism, as if the call took the form of 
  43. > x-> X::function().  That is to say, all calls on X's are in the explicit 
  44. > scope of X.  (Language lawyers please refine)
  45.  
  46. The 'normal' function mechanism can be used for any method not
  47. declared as virtual. The only exception I can think of is when a base
  48. class declares a virtual function you do not want to reimplement, but
  49. you also do not want to pay for the cost of virtual invocations:
  50.  
  51. class Base {
  52. public:
  53.   virtual void foo();
  54. };
  55.  
  56. inline void Base::foo() {}
  57.  
  58. class Derived : public Base {};
  59.  
  60. main() {
  61.   Derived X;
  62.   X.foo();
  63. }
  64.  
  65. You can allow foo's code to be inlined by changing the declaration of
  66. Derived to:
  67.  
  68. class Derived : public Base {
  69. public:
  70.   inline void foo() { Base::foo(); }
  71. };
  72.  
  73. Since Derived::foo is not virtual, in can be inlined, as well as
  74. Base::foo could, since it is given a scope specifier. Although this
  75. requires some more lines of code, no changes in the standard are
  76. required.
  77. -- 
  78. Alexandre Oliva
  79. oliva@dcc.unicamp.br
  80. Universidade Estadual de Campinas, S~ao Paulo, Brasil
  81.  
  82. [ To submit articles: Try just posting with your newsreader.
  83.               If that fails, use mailto:std-c++@ncar.ucar.edu
  84.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  85.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  86.   Comments? mailto:std-c++-request@ncar.ucar.edu
  87. ]
  88.